using Godot;
using System;

public partial class WeaponSelectionItem : MarginContainer
{
	[Signal]
	public delegate void OnSelectEventHandler(WeaponEntity weapon);
	Label weaponName;
	Label atkOcean;
	Label atkLand;
	Label atkAir;
	Label hitRate;
	Label range;
	Button selectButton;

	MarginContainer m31;
	MarginContainer m32;
	Label weaponDisc;

	WeaponEntity entity;

	void GetChildComponents()
	{
		m31 = GetNode<MarginContainer>("%M31");
		m32 = GetNode<MarginContainer>("%M32");
		weaponDisc = GetNode<Label>("%WeaponDisc");
		weaponName = GetNode<Label>("%WeaponName");
		atkOcean = GetNode<Label>("%AtkOcean");
		atkLand = GetNode<Label>("%AtkLand");
		atkAir = GetNode<Label>("%AtkAir");
		hitRate = GetNode<Label>("%HitRate");
		range = GetNode<Label>("%Range");
		selectButton = GetNode<Button>("Button");
		selectButton.Pressed += OnSelectButtonPressed;
	}

	private void OnSelectButtonPressed()
	{
		if (GameManager.Instance.IsLockInput) return;
		EmitSignal(SignalName.OnSelect, entity);
	}

	public override void _Ready()
	{
		base._Ready();
		GetChildComponents();
	}

	public void SetInfo(WeaponEntity weapon)
	{
		entity = weapon;
		if (weapon.StringID == "HealSkill")
		{
			m31.Hide();
			m32.Show();
			weaponDisc.Text = weapon.SkillDescription;
		}
		else
		{
			m31.Show();
			m32.Hide();
			atkOcean.Text = weapon.AttackOcean.ToString();
			atkLand.Text = weapon.AttackLand.ToString();
			atkAir.Text = weapon.AttackAir.ToString();
			hitRate.Text = weapon.HitRate.ToString();
		}
		weaponName.Text = weapon.WeaponName;
		if (weapon.CastType == SkillCastType.NoTarget)
		{
			range.Text = weapon.Radius.ToString();
		}
		else
		{
			range.Text = weapon.RangeMax.ToString();
		}
	}
}
